package com.jyw.business.obstacles.controller;

import com.jyw.business.obstacles.domain.dto.web.*;
import com.jyw.business.obstacles.domain.vo.web.MineOrderCountVO;
import com.jyw.business.obstacles.domain.vo.web.MineOrderPageVO;
import com.jyw.business.obstacles.service.IObsOrderMakeService;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 沈峻
 * @ClassName ObsMineOrderController
 * @Description 我的工单接口
 * @Date 2023/8/11 17:31
 **/
@RestController
@RequestMapping("/obstacles/mine/order")
@Api(tags = "我的工单")
public class ObsMineOrderController extends BaseController {

    @Resource
    private IObsOrderMakeService orderMakeService;

    @PostMapping("page")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:page')")
    @ApiOperation("分页查询")
    public TableDataInfo<MineOrderPageVO> page(@RequestBody MineOrderPageDto pageDto){
        startPage();
        return getDataTable(orderMakeService.orderPage(pageDto));
    }

    @GetMapping("count")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:page')")
    @ApiOperation("分页查询统计")
    public CommonResult<MineOrderCountVO> count(){
        return CommonResult.success(orderMakeService.orderPageCount());
    }


    @PutMapping("receive")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:receive')")
    @ApiOperation("接单")
    public CommonResult receive(@RequestBody ReceiveOrderDto orderDto){
        orderMakeService.receive(orderDto);
        return CommonResult.success();
    }


    @PutMapping("complete")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:make')")
    @ApiOperation("完成工单")
    public CommonResult complete(@RequestBody CompleteOrderDto orderDto){
        orderMakeService.complete(orderDto);
        return CommonResult.success();
    }

    @PutMapping("make")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:make')")
    @ApiOperation("处理工单")
    public CommonResult make(@RequestBody MakeOrderDto orderDto){
        orderMakeService.make(orderDto);
        return CommonResult.success();
    }

    @PutMapping("assist")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:make')")
    @ApiOperation("协作工单")
    public CommonResult assist(@RequestBody AssistOrderDto orderDto){
        orderMakeService.assist(orderDto);
        return CommonResult.success();
    }


    @PutMapping("upgrade")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:make')")
    @ApiOperation("升级工单")
    public CommonResult upgrade(@RequestBody OrderUpgradeDto orderDto){
        orderMakeService.upgrade(orderDto);
        return CommonResult.success();
    }

    @PutMapping("reback")
    @PreAuthorize("@ss.hasAnyPermi('obstacles:mine:order:reback')")
    @ApiOperation("退单")
    public CommonResult reback(@RequestBody OrderRebackDto orderDto){
        orderMakeService.reback(orderDto);
        return CommonResult.success();
    }

    @PutMapping("suspend")
    @PreAuthorize("@ss.hasAnyPermi('obstacles:server:suspend,obstacles:mine:order:suspend')")
    @ApiOperation("暂停")
    public CommonResult suspend(@RequestBody OrderSuspendDto orderDto){
        orderMakeService.suspend(orderDto);
        return CommonResult.success();
    }

    @PutMapping("open")
    @PreAuthorize("@ss.hasAnyPermi('obstacles:server:open,obstacles:mine:order:open')")
    @ApiOperation("开启")
    public CommonResult open(@RequestBody BaseOrderDto orderDto){
        orderMakeService.open(orderDto);
        return CommonResult.success();
    }

    @PutMapping("termination")
    @PreAuthorize("@ss.hasAnyPermi('obstacles:mine:order:termination,obstacles:server:termination')")
    @ApiOperation("终止")
    public CommonResult termination(@RequestBody OrderTerminationDto orderDto){
        orderMakeService.termination(orderDto);
        return CommonResult.success();
    }

    @PutMapping("restart")
    @PreAuthorize("@ss.hasAnyPermi('obstacles:server:restart,obstacles:mine:order:restart')")
    @ApiOperation("重启")
    public CommonResult restart(@RequestBody BaseOrderDto orderDto){
        orderMakeService.restart(orderDto);
        return CommonResult.success();
    }


    @PutMapping("redirect")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:redirect')")
    @ApiOperation("转单")
    public CommonResult redirect(@RequestBody OrderRedirectDto orderDto){
        orderMakeService.redirect(orderDto);
        return CommonResult.success();
    }





}
